/**
 *	\brief		Include product specific JavaScript
*/
TM_ProductLang = new ProductLang("modProduct");
if(wfc_js_compact === true)
{
    //include compact javascript
}
else
{
    //include non-compact javascript 
}
IncludeJavaScript(homeBase+WP_WEBROOT_NO_SLASH+'/widgetBase/modBaseWidget/js/tmBoxWindow.js');

if(wfconf_use_highcharts == true){
	if(wfc_js_compact == true){
		IncludeJavaScript(homeBase+'lib/Highcharts/js/adapters/mootools-adapter.js');
		IncludeJavaScript(homeBase+'lib/Highcharts/js/highcharts.js');
	}else{
		IncludeJavaScript(homeBase+'lib/Highcharts/js/adapters/mootools-adapter.src.js');
		IncludeJavaScript(homeBase+'lib/Highcharts/js/highcharts.src.js');
	}
	if(wfconf_use_fushion2highcharts_adapter == true){
		IncludeJavaScript(homeBase+WP_WEBROOT_NO_SLASH+'/widgetBase/modProduct/js/adapter.js');
	}
}

if(wfconf_use_jquery){
    if(wfc_js_compact == true){
        if (wfc_use_jquery_common_ui){
            IncludeJavaScript(homeBase+'/lib/jQuery/jquery.event.drag.min.js');
            IncludeJavaScript(homeBase+'/lib/jQuery/jquery.event.drop.min.js');
            IncludeJavaScript(homeBase+'/lib/json/json2.min.js');
            IncludeJavaScript(homeBase+'/lib/jQuery/scroll-startstop.events.jquery.min.js');
        }
    }else{
        if (wfc_use_jquery_common_ui){
            IncludeJavaScript(homeBase+'/lib/jQuery/jquery.event.drag.js');
            IncludeJavaScript(homeBase+'/lib/jQuery/jquery.event.drop.js');
            IncludeJavaScript(homeBase+'/lib/json/json2.js');
            IncludeJavaScript(homeBase+'/lib/jQuery/scroll-startstop.events.jquery.js');
        }
    }
    if (wfc_use_jquery_common_ui){
        IncludeJavaScript(homeBase+'ui/trendContextMenu/jquery.trendContextMenu.js');
        WF_loadCSS(homeBase+'ui/trendContextMenu/jquery.contextMenu.osce.css');
        WF_loadCSS(homeBase+'ui/trendContextMenu/jquery.contextMenu.osce.button.css');
        IncludeJavaScript(homeBase+'ui/trendgrid/jquery.trendGrid.js');
        WF_loadCSS(homeBase+'ui/trendgrid/trend-grid.css');
        IncludeJavaScript(homeBase+'ui/trendtree/jquery.trendTree.js');
        WF_loadCSS(homeBase+'ui/trendtree/trend-tree.css');
    }
}

/**
 *	\brief		Product global specific variable
*/
var TM_Lang;
/**
 *	\brief		Add product specific additional parameter in the URL
 *
 *	\return		the additional url want append to the request URL
*/
function AddUrlParam()
{
	return "";
}

/**
 *	\brief		The index.php body onload event handler for product
*/
function WidgetMainPageOnload()
{
	// You can do any additional tasks in this function	
    TM_Lang = new ProductLang("modBaseWidget");
}

/**
 *	\brief		Include Additional Script file after successful login
*/
function IncludeAdditionalScript()
{
	if(wfconf_use_highcharts == true){
		// Please do not change below color before approved by HIE
		var arrColorTrendMicroStandard = ['#1F78B4', '#91C8F0', 
			              		            '#FF7f00', '#FFAA46', 
			            		            '#33A02C', '#96D56B', 
			            		            '#E01215', '#F78CA1', 
			            		            '#6A3D9A', '#BE95D3'];
		Highcharts.setOptions({
			chart: {
				reflow: false, // default turn off reflow due to IE7,IE8 cause autofix problem
				animation: false, // default turn off animation due to performance issue
				marginBottom: 80, // define legend block and chart margin
				style: {
					fontFamily: 'Arial' // default font
				}
			},
			title: {
	 			 align: 'center',
                 style: {
                    color:'#333333',
                    fontSize:14
                 }
	 		  },
	 		  subtitle: {
	 			 align: 'center',
                 style: {
                    color:'#464646',
                    fontSize:11
                 }
	 		  },
		    credits: {enabled: false},
		    legend: {
				layout: 'horizontal',
				align: 'center',
				verticalAlign: 'bottom',
				floating: true,
				borderWidth: 1,
				backgroundColor: '#FFFFFF', //fix IE9 y-Xsis title anti-alias problem
                itemStyle: {
                    color: '#333333',
                    fontSize:11
                }
			},
			xAxis: {
                tickmarkPlacement:'on',
                tickColor:'#5B5353',
				labels: {
                    y:17
	            }
	 		},
            yAxis: {
                  title: {
                      style: {
                          color: "#000000",
                          fontWeight: "bold",
                          backgroundColor: '#FFFFFF'
                      }
                  }
	 		},
		    colors: arrColorTrendMicroStandard
		});
	}
}

/**
 *	\brief		Customized function to detect session timeout
*/
function WFC_isSessionExpired(RequestObject, response_text)
{
	// You have 2 things to check 'session expired'
	// 1.RequestObject (XMLHttpRequest Object), which is xhr object
	//   - Get header: RequestObject.getResponseHeader(name)
	//   - Get response code: RequestObject.status. (200, 302, 403, 404, 500, ...)
	// 2.response_text: response content
	//   - Please note that when request is failure, response_text might be 'null'.
	return false;
}

/**
 *	\brief		Customized function to detect session timeout
*/
function WFC_handler_SessionExpired(RequestObject, response_text)
{
	// now session expired, do whatever you want.
}
function IncludeIEJavaScript(jsFile)
{
	document.write('<!--[if IE]><script type="text/javascript" src="' + jsFile + '"></scr' + 'ipt><![endif]-->'); 
}
function WF_loadCSS(filepath) 
{
    document.write('<link rel="stylesheet" href="' + filepath + '"/>'); 
}

/**
 *	\brief	Add cells into a table row
*/
function addCell(tr, content, attrs, td_type) {
    var tag = td_type||'td';
    var td = tr.appendChild(document.createElement(tag));
    if(!attrs) attrs = {};
    for(n in attrs){
        if(n=='class')  { td.className=attrs[n]         }
        else            { td.setAttribute(n,attrs[n]);  }
    }
    if(typeof content=='string' || typeof content=='number') {
        td.innerHTML = content==''?'&nbsp;':content;   
    }
    else { 
        td.appendChild(content);
    }
    return td;
}
